<?php
declare (strict_types = 1);

namespace app\api\controller\app;

class Base extends \app\api\controller\Base
{
	protected $uuid = 0;
	
	public function initialize(){
		parent::initialize();
		$this->uuid=I('ssid',0);
		$token=I('get.tk','');
		$m_token=\core\Encode::minapp_api_md5($this->uuid);
		if($this->uuid===0 || $token==='') return $this->p_error('缺少SSID！');
		if($token!=$m_token) return $this->p_error('token验证失败！');
	}
	
	//替换图片路径
	protected function host_images($list,$key=[]){
		$host = get_api_host();
		if(is_array($list)){
			if(!is_array($key)) $key=[$key];
			foreach($list as &$v){
				foreach($key as $k){
					if($v[$k]!='' && $this->is_http($v[$k])==false){
						$v[$k]=$host . $v[$k];
					}
				}
			}
		}else if($list!="" && $this->is_http($list)==false){
			$list = $host . $list;
		}
		return $list;
	}
	
	//是否HTTP开头
	protected function is_http($url){
		if(substr($url,0,7)=="http://" || substr($url,0,8)=="https://"){
			return true;
		}else{
			return false;
		}
	}
}
